Skip to content

[don't merge yet] Pool QueueWithRetry and cache filterDirtyFiles regexp#19544

Open
AlexeyAkhunov wants to merge 1 commit intomainfrom
pool-queue-cache-regexp
Open

[don't merge yet] Pool QueueWithRetry and cache filterDirtyFiles regexp#19544
AlexeyAkhunov wants to merge 1 commit intomainfrom
pool-queue-cache-regexp

Conversation

@AlexeyAkhunov
Copy link
Contributor

Summary

  • QueueWithRetry pooling (execution/exec/txtask.go): Add sync.Pool for QueueWithRetry with a Release() method that drains the 100K-element channel without closing it, preserving the ~1.6MB buffer across reuses. parallelExecutor.run calls Release() instead of Close(); workers exit via ctx.Done(). Cleanup ordering ensures stopWorkers() completes before Release() to avoid races.
  • filterDirtyFiles regexp cache (db/state/dirty_files.go): Cache compiled regexps in a sync.Map keyed by pattern string. Each unique (filenameBase, ext) pair compiles once instead of on every call.

Profiling testlab test runs showed QueueWithRetry allocation at 79.5GB (18.8% of total allocs) and filterDirtyFiles regexp at 14.6GB (3.3%). Combined expected savings: ~94GB (22% of total allocations).

Test plan

  • Verify go build ./... passes
  • Run go test ./execution/exec/... and go test ./execution/stagedsync/... and go test ./db/state/...
  • Run full CI suite to check for regressions

🤖 Generated with Claude Code

@AskAlexSharov AskAlexSharov enabled auto-merge (squash) March 1, 2026 09:50
@AlexeyAkhunov AlexeyAkhunov force-pushed the pool-queue-cache-regexp branch 2 times, most recently from aabd358 to b6d591f Compare March 1, 2026 12:10
@AlexeyAkhunov
Copy link
Contributor Author

Looks like changes in this PR make the flaky test reproducible. I am using it to debug that flaky test

@AlexeyAkhunov AlexeyAkhunov changed the title Pool QueueWithRetry and cache filterDirtyFiles regexp [don't merge yet] Pool QueueWithRetry and cache filterDirtyFiles regexp Mar 1, 2026
…l executor lifecycle

Three changes:

1. Pool QueueWithRetry via sync.Pool — avoids reallocating the 100K-element
   channel buffer on every block when ExperimentalBAL is enabled.
   Release() is idempotent (safe against double-call from deferred cleanup).

2. Cache compiled regexps in filterDirtyFiles via sync.Map.

3. Fix parallel executor cleanup ordering: wait for the exec loop goroutine
   to fully exit before stopping workers or releasing the queue. Without this,
   Release() can pool the queue while the exec loop is still calling Add(),
   leading to cross-test contamination.

4. Fix scheduleExecution: clear inProgress before re-pushing skipped tasks
   to pending (prevents phantom in-progress state). Add force-schedule
   fallback when all pending tasks are speculatively skipped to prevent
   deadlock.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@AlexeyAkhunov AlexeyAkhunov force-pushed the pool-queue-cache-regexp branch from f5d7e7d to c0a4e11 Compare March 2, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants